package com.example.repo;

import java.util.Map;

import com.example.domain.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class PersonRepoImpl implements PersonRepo {

	@Autowired
	private RedisTemplate<String, Object> redisTemplate;

	private static String KEY = "Person";

	@Override
	public void save(Person person) {
		this.redisTemplate.opsForHash().put(KEY, person.getIdNum(), person);
	}

	@Override
	public Person find(String id_num) {
		return (Person) this.redisTemplate.opsForHash().get(KEY, id_num);
	}

	@Override
	public Map<Object, Object> findAll() {
		return this.redisTemplate.opsForHash().entries(KEY);
	}

	@Override
	public void delete(String id_num) {
		this.redisTemplate.opsForHash().delete(KEY, id_num);
	}
}
